<?php

namespace app\index\controller;

use think\Db;

class Job extends Base
{

    /**
     * 添加岗位
     */
    public function addJob()
    {
        $data = [];
        input('name') ? $data['name'] = input('name') : $this->err('缺少职责');
        $data['createTime'] = createTime();

        $res = model('job')->editData($data);
        $res ? $this->suc($res) : $this->err('添加岗位失败');
    }

    /**
     * 修改岗位
     */
    public function editJob()
    {
        $data = [];
        input('id') ? $data['id'] = input('id') : $this->err('缺少岗位主键');
        input('name') ? $data['name'] = input('name') : $this->err('缺少岗位');

        $res = model('job')->editData($data, $data['id']);
        $res ? $this->suc($res) : $this->err('修改岗位失败');
    }

    /**
     * 删除岗位
     */
    public function delJob()
    {
        $where = [];
        input('id') ? $where['id'] = input('id') : $this->err('缺少岗位主键');

        $res = model('job')->where($where)->delete();
        $res ? $this->suc($res) : $this->err('删除岗位失败');

    }

    /**
     * 查询岗位
     */
    public function getJobList()
    {
        $where = [];
        input('name') ? $where['name']=['like','%'.input('name').'%'] : true;



        $res = model('job')->where($where)->order('sort desc')->select();
        $res ? $this->suc($res) : $this->err('删除岗位失败');

    }

}
